package dfsketches.bicycles;

import java.util.Arrays;

public class PackedArray {
	private int size;
	private int[] start;
	private int[] value;
	
	public PackedArray() {
		this(1);
	}
	
	public PackedArray(int capacity) {
		size = 0;
		start = new int[capacity];
		value = new int[capacity];
	}
	
	public void put(int idx, int val) {
		start[size] = idx;
		value[size] = val;
		
		size++;
		if (size == start.length) {
			start = Arrays.copyOf(start, size*2);
			value = Arrays.copyOf(value, size*2);
		}
	}
	
	public int get(int idx) {
		int i = 0;
		while (i+1 < size && start[i+1] < idx) i++;
		return value[i];
	}
}
